package com.qingzhu.controller.orderserver;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.qingzhu.pojovo.ResultVo;
import com.qingzhu.service.OrderService;
import com.qingzhu.service.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/order/delete")
public class OrderDeleteController extends HttpServlet {
    OrderService orderService = new OrderServiceImpl();
    ObjectMapper objectMapper = new ObjectMapper();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("订单删除服务..");

        String server = req.getParameter("server");
        if (server == null){
            deleteOrder(req,resp);
        }
    }


    // 将订单标记为删除
    public void deleteOrder(HttpServletRequest req, HttpServletResponse resp) throws IOException{
        String orderId = req.getParameter("orderId");
        int result = orderService.deleteOrderById(Integer.parseInt(orderId));
        ResultVo resultVo = result>0 ? new ResultVo(200,"删除成功！"):new ResultVo(500,"删除失败！");
        resp.getWriter().write(objectMapper.writeValueAsString(resultVo));
    }
}
